package com.itfreer.gis.map;

import com.itfreer.sso.base.services.JsonPathPara;
import com.itfreer.sso.client.SsoClientConfig;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.itfreer.file.FilePathPara;
import com.itfreer.file.LocalFilePathPara;
import com.itfreer.gis.server.storage.StoragePara;
import com.itfreer.jwt.JwtPara;
import com.itfreer.jwt.SystemParameter;
import com.itfreer.utils.BaseHost;
import com.itfreer.utils.file.FileMeta;
import com.itfreer.utils.file.FilePara;

/**
 * 定义平台通用配置 将所有常需要改动的地方，全部集中在此配置文件
 */
@Configuration
public class ProConfiguration {

	private String path = "/Volumes/work/share/data";
	private String serviceName = "http://localhost:4200";
	private String baseUrl = "http://localhost:81/";

	/**
	 * 获取后台服务基础路径
	 * 
	 * @return
	 */
	@Bean
	public BaseHost baseHost() {
		BaseHost baseHost = new BaseHost();
		baseHost.setBaseUrl(baseUrl);
		return baseHost;
	}

	/**
	 * 当前系统参数
	 * 
	 * @return
	 */
	@Bean(name = "systemParameter")
	public SystemParameter systemParameter() {
		SystemParameter config = new SystemParameter();
		config.setsId("pro");
		return config;
	}

	/**
	 * 文件下载地址 主要是解决文件服务器问题
	 * 
	 * @return
	 */
	@Bean
	public FilePara filePara() {
		return new FilePara() {
			@Override
			public String getDownloadUrl(FileMeta file) {
				return baseUrl + file.getBucketName() + "/" + file.getKey();
			}
		};
	}

	/**
	 * jwt票据参数
	 * 
	 * @return
	 */
	@Bean
	public JwtPara jwtPara() {
		JwtPara bean = new JwtPara();
		List<String> urls = new ArrayList<>();
		urls.add(serviceName);
		urls.add("http://www.itfreer.com");
		bean.setSecurityUrls(urls);
		return bean;
	}

	/**
	 * 文件存储目录 如果文件服务器为目录存储形式
	 * 
	 * @return
	 */
	@Bean
	public FilePathPara filePathPara() {
		FilePathPara para = new FilePathPara();
		para.setFilePath(path + "/file");
		return para;
	}

	/**
	 * 本地文件服务目录
	 * 
	 * @return
	 */
	@Bean
	public LocalFilePathPara localFilePathPara() {
		LocalFilePathPara para = new LocalFilePathPara();
		para.setFilePath(path + "/file");
		return para;
	}

	/**
	 * 如果是单点登录服务端 注册服务的存储目录
	 * 
	 * @return
	 */
	@Bean(name = "jsonPathPara")
	public JsonPathPara jsonPathPara() {
		JsonPathPara para = new JsonPathPara();
		para.setFilePath(path + "/service");
		return para;
	}

	/**
	 * 单点登录配置
	 * 
	 * @return
	 */
	@Bean(name = "ssoClientConfig")
	public SsoClientConfig ssoClientConfig() {
		String loginUrl = baseUrl + "static/login/index.html";
		SsoClientConfig config = new SsoClientConfig();
		config.setServiceName(serviceName);
		config.setAllowAnyProxy(false);
		config.setLoginUrl(loginUrl);
		config.setLogoutRedirectUrl(loginUrl + "?service=" + serviceName);
		return config;
	}
	
	/**
     * GIS服务切片存储参数
     *
     * @return
     */
    @Bean(name = "storagePara")
    public StoragePara storagePara() {
        StoragePara para = new StoragePara();
        para.setEndpoint("http://47.106.79.19:9000");
        para.setAccessKey("minio");
        para.setSecretKey("123!@#qweQWE@ITFREER");
        return para;
    }
}
